var ArticleCategroyApp = function(){
	return{
		init:function(){
			ArticleCategroyApp.loadGrid();
		},
		loadGrid:function(){
    		var url = $("#APP_ROOT_PATH").val() + 'article_catgory/pageData';
    		gui.widgets.BootStrap.loadGrid({
                gridSelector:"#grid-table",
                pagerSelector:"#grid-pager",
                postData:{
                },
                jsonReader : {
                    root: "data.rows",
                    records: "data.total",
                    repeatitems : false,
                    total: function (obj) {
                        return  Math.ceil(obj.data.total /jQuery("#grid-table").getGridParam("rowNum"));
                    }
                } ,
                datatype: 'json',
                url:url,
                colNames:['分类名称','创建时间','操作'],
                colModel:[{name:'name'},
                          {name:'gmtCreate'},
                          {name:'操作',index:'', width:30,sortable:false,formatter:function(cellvalue,options,rowObject){
                          	return "<div>"+
                          	gui.widgets.BootStrap.colButton("icon-edit","编辑","ArticleCategroyApp.edit("+rowObject.id+")")+
                          	//<a target=\"view_window\" href='"+$("#APP_ROOT_PATH").val()+"message/detail_index?id="+rowObject.id+"'>"+gui.widgets.BootStrap.colButton("icon-edit")+"</a>"
                          	//"<a target=\"view_window\" href='"+$("#APP_ROOT_PATH").val()+"article_catgory/editor_window?id="+rowObject.id+"'>"+gui.widgets.BootStrap.colButton("icon-edit")+"</a>"+
      						gui.widgets.BootStrap.colButton("icon-trash","删除","ArticleCategroyApp.del("+rowObject.id+")")+
      						"</div>";
                          }}
                ],
                caption: "",
                rowList:[10,20,30],
                multiselect: true,
                prmNames:{
                    page:"pageNum",
                    rows:"pageSize",
                    sort: "sortField",
                    order: "sortOrder",
                    search:"_search"
                }
            });
    	},
    	reload:function(){
    		jQuery("#grid-table").jqGrid('setGridParam',{page:1}).trigger("reloadGrid");
    	},
    	reset:function(){
    		$("#ownerName").val('');
    		$("#type").val('');
    	},
    	edit:function(id){
    		var url = $("#APP_ROOT_PATH").val() + "article_catgory/editor_window?id="+id;
			layer.open({
				type: 2,
				area: ['300px', '100px'],
				fix: false, //不固定
				maxmin: false,
				content: url
			});
    	},
    	/**
    	 * 修改分类名
    	 */
    	alterName:function(id){
    		var id = $("#id").val();
    		var name = $("#td").val();
    		gui.util.Ajax.asyncGET(
        			$("#APP_ROOT_PATH").val() + "article_catgory/edit",
        			{
        				'id':id,
        				'name':name
        			},
    				function(data){
        				if(data==true){
        					layer.msg('修改成功', {
    							icon: 1
    						});
        					setTimeout(function(){
        						parent.location.reload();
        					}, 1000)
        				}else{
        					layer.msg('修改失败', {
    							icon: 0
    						});
        				}
            		},
    				function(){
    				},
    				function(){
    					//layer.load();
    				},
    				function(){
    					layer.closeAll();
    				}
    			)
    	},
		editgroup: function() {
			var url = $("#APP_ROOT_PATH").val() + "article_catgory/open_window";
			layer.open({
				type: 2,
				area: ['300px', '100px'],
				fix: false, //不固定
				maxmin: false,
				content: url
			});
		},
		del:function(id){
			if(confirm("确定要要删除该用户信息吗?")){
				var url = $("#APP_ROOT_PATH").val() + '/article_catgory/del';
				gui.util.Ajax.asyncGET(url,{id:id},function(res){
					if(res.data == true){
						layer.msg('删除成功', {
							icon: 1
						});
						setTimeout(function(){
							location.reload();
						},1000)
					}
					if(res.data == false){
						layer.msg('此分类中还有文章，不可以删除！', {
							icon: 0
						});
					}
				});
			}
			return false;
		},
		/**
		 * 保存分类名
		 */
		saveName:function(){
			var name = $("#name").val();
			gui.util.Ajax.asyncGET(
        			$("#APP_ROOT_PATH").val() + "article_catgory/saveData",
        			{
        				'name':name
        			},
    				function(data){
						if(data > 0){
							layer.msg('保存成功', {
								icon: 1
							});
							setTimeout(function(){
								parent.location.reload();
							},1000)
						}else{
							layer.msg('保存失败', {
								icon: 0
							});
						}
            		},
    				function(){
    				},
    				function(){
    					//layer.load();
    				},
    				function(){
    					layer.closeAll();
    				}
    			)
		},
	}
}();